Skip to content

feat: NativeAOT-compatible JSON serialization via source generation#5

Merged
nlogozzo merged 8 commits into
mainfrom
copilot/make-project-nativeaot-compatible
Mar 20, 2026
Merged

feat: NativeAOT-compatible JSON serialization via source generation#5
nlogozzo merged 8 commits into
mainfrom
copilot/make-project-nativeaot-compatible

Conversation

Copilot AI commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Reflection-based System.Text.Json usage throughout the library prevents <PublishAot>true</PublishAot> publishing. This PR replaces all reflection-based serialization with source-generation-backed alternatives across all serialization sites.

Changes

IJsonFileService / JsonFileService

  • Replaced all methods with JsonTypeInfo<T>-based overloads for Load, LoadAsync, Save, SaveAsync — the only API is now AOT-safe, using new T() (where T : new()) instead of Activator.CreateInstance<T>()
  • Removed reflection-based JsonSerializerOptions static field and static constructor

Consumers provide their source-generated context's type info:

[JsonSerializable(typeof(Config))]
internal partial class AppJsonContext : JsonSerializerContext { }

// AOT-safe:
var config = jsonFileService.Load(AppJsonContext.Default.Config);
jsonFileService.Save(config, AppJsonContext.Default.Config);

UpdaterService

  • Added internal UpdaterServiceJsonContext (JsonSerializerContext with SnakeCaseLower naming) for List<GitHubRelease> and GitHubReleaseAsset
  • Replaced the Octokit→JSON→GitHubRelease round-trip with direct manual mapping, eliminating the need to source-generate external Octokit types
  • Replaced GetFromJsonAsync<T>(url, JsonSerializerOptions) with the JsonTypeInfo<T> overload
  • Removed the static JsonSerializerOptions field

ObjectExtensions

  • Added DeepCopy(JsonTypeInfo<T>) overload alongside the existing (now annotated) reflection-based one

JSON Converters

  • NullToZeroIntConverter, NullToFalseBoolConverter, NullToTrueBoolConverter, NullToEmptyStringConverter: replaced JsonSerializer.Deserialize/Serialize with Utf8JsonReader/Utf8JsonWriter primitives directly, eliminating IL2026/IL3050 AOT warnings
  • NullToDefaultValueConverter<T> and NullToDefaultObjectConverter<T>: replaced reflection-based JsonSerializer calls with options.GetTypeInfo(typeof(T)) → AOT-safe JsonTypeInfo<T> overloads; added where T : new() constraint on NullToDefaultObjectConverter<T>

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 2 commits March 18, 2026 15:07
Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>
…e path construction)

Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>
Copilot AI changed the title [WIP] Add NativeAOT compatibility for project feat: NativeAOT-compatible JSON serialization via source generation Mar 18, 2026
Copilot AI requested a review from nlogozzo March 18, 2026 15:13
@nlogozzo

Copy link
Copy Markdown
Member

@copilot I've updated the code - I want this library to always use source generated route instead of the non native-aot compatable apis. Please look at the changes and fix jsonfileservice tests. The tests should just use the sourcegen methods and the old cases should be removed. Rename the case00#

…unused JsonOptions

Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>

Copilot AI commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot I've updated the code - I want this library to always use source generated route instead of the non native-aot compatable apis. Please look at the changes and fix jsonfilese...

Done in 6a62246. Removed Cases 001–008 (reflection-based API) from JsonFileServiceTests, renamed the source-gen cases to Case001–Case008, and also removed the now-unused JsonOptions static field and static constructor from JsonFileService.cs.

@nlogozzo

Copy link
Copy Markdown
Member

@copilot Seeing these warnings:

1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(15,16,15,68): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(15,16,15,68): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(15,16,15,66): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(15,16,15,66): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(18,98,18,146): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(18,98,18,146): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(18,100,18,148): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(18,100,18,148): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(15,16,15,69): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(15,16,15,69): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(18,101,18,149): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(18,101,18,149): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(15,16,15,69): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(15,16,15,69): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(18,101,18,149): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(18,101,18,149): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(15,16,15,71): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(15,16,15,71): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(18,103,18,151): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(18,103,18,151): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(15,16,15,66): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(15,16,15,66): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(18,98,18,146): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(18,98,18,146): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>  Nickvision.Desktop -> C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\bin\Debug\net9.0-windows10.0.19041.0\Nickvision.Desktop.dll
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(15,16,15,45): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(15,16,15,45): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(15,16,15,47): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(15,16,15,47): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(18,98,18,122): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(18,98,18,122): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(18,100,18,124): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(18,100,18,124): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(15,16,15,48): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(15,16,15,48): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(18,101,18,125): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(18,101,18,125): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(15,16,15,48): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(15,16,15,48): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(18,101,18,125): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(18,101,18,125): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(15,16,15,50): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(15,16,15,50): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(18,103,18,127): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(18,103,18,127): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(15,16,15,45): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(15,16,15,45): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(18,98,18,122): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(18,98,18,122): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>  Nickvision.Desktop -> C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\bin\Debug\net10.0-windows10.0.19041.0\Nickvision.Desktop.dll
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(15,16,15,68): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(15,16,15,68): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(18,100,18,148): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(18,100,18,148): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(15,16,15,69): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(15,16,15,69): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(18,101,18,149): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToTrueBoolConverter.cs(18,101,18,149): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(18,101,18,149): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(18,101,18,149): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(15,16,15,69): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToFalseBoolConverter.cs(15,16,15,69): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(15,16,15,66): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(15,16,15,66): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(15,16,15,71): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(15,16,15,71): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(18,98,18,146): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultValueConverter.cs(18,98,18,146): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(18,103,18,151): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToEmptyStringConverter.cs(18,103,18,151): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(15,16,15,66): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(15,16,15,66): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(ref Utf8JsonReader, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(18,98,18,146): warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.
1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToDefaultObjectConverter.cs(18,98,18,146): warning IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.

Please make AOT compatible.

Co-authored-by: nlogozzo <17648453+nlogozzo@users.noreply.github.com>

Copilot AI commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Seeing these warnings:

1>C:\Users\nlogozzo\OneDrive\Documents\Programming\Desktop\Nickvision.Desktop\Converters\NullToZeroIntConverter.cs(15,16,15,68): warning IL2026:...

Fixed in fd543dd. All six converters now use AOT-safe primitives:

  • NullToZeroIntConverter, NullToFalseBoolConverter, NullToTrueBoolConverter, NullToEmptyStringConverter — replaced JsonSerializer.Deserialize/Serialize with the corresponding Utf8JsonReader/Utf8JsonWriter primitives (GetInt32, GetBoolean, GetString, WriteNumberValue, etc.)
  • NullToDefaultValueConverter<T> and NullToDefaultObjectConverter<T> — use options.GetTypeInfo(typeof(T)) to get the JsonTypeInfo<T> and pass it to the JsonTypeInfo<T> overloads of JsonSerializer.Deserialize/Serialize, which are the AOT-safe path

@nlogozzo nlogozzo marked this pull request as ready for review March 20, 2026 03:01
@nlogozzo nlogozzo merged commit a369875 into main Mar 20, 2026
11 checks passed
@nlogozzo nlogozzo deleted the copilot/make-project-nativeaot-compatible branch March 20, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants